package com.free.mini.core.serve.controller;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.free.mini.common.base.ResultData;
import com.free.mini.core.serve.service.IStudyModuleService;
import com.free.mini.core.server.vo.req.StudyModuleCreateReqVO;
import com.free.mini.core.server.vo.req.StudyModuleQueryReqVO;
import com.free.mini.core.server.vo.req.StudyModuleUpdateReqVO;
import com.free.mini.core.server.vo.resp.StudyModuleQueryRespVO;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 学习模块
 * 
 * @author dongsufeng
 * @version 4.0
 * @date 2023/8/1 15:30
 */
@RestController
@RequestMapping("study/v1/module/")
@Slf4j
@RequiredArgsConstructor
public class StudyModuleController {

    private final IStudyModuleService studyModuleService;

    /**
     * 模块列表
     * 
     * @return
     */
    @PostMapping("list")
    public ResultData<List<StudyModuleQueryRespVO>> list(@RequestBody StudyModuleQueryReqVO reqVO) {
        return ResultData.data(studyModuleService.findStudyModules(reqVO));
    }
    /**
     * 模块详情
     *
     * @return
     */
    @PostMapping("detail")
    public ResultData<StudyModuleQueryRespVO> detail(@RequestBody StudyModuleQueryReqVO reqVO) {
        return ResultData.data(studyModuleService.detail(reqVO));
    }
    /**
     * 新增模块
     * @param reqVO
     * @return
     */
    @PostMapping("create")
    public ResultData<Boolean> create(@RequestBody @Validated StudyModuleCreateReqVO reqVO){
        return ResultData.data(studyModuleService.createStudyModule(reqVO));
    }

    @PostMapping("update")
    public ResultData<Boolean> update(@RequestBody @Validated StudyModuleUpdateReqVO reqVO){
        return ResultData.data(studyModuleService.updateStudyModule(reqVO));
    }

    @PostMapping("page")
    public ResultData<Page<StudyModuleQueryRespVO>> page(@RequestBody StudyModuleQueryReqVO reqVO){
        return ResultData.data(studyModuleService.page(reqVO));
    }
}
